package com.hxzy.service.impl;

import com.hxzy.mapper.MyBatisBaseDao;
import com.hxzy.service.IService;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 通用的业务逻辑实现(新增，修改，删除，根据主键查询)
 * @param <Model>
 * @param <PK>
 */
public class ServiceImpl<Model, PK extends Serializable> implements IService<Model,PK> {

    /**
     * 多态的体现
     */
    private MyBatisBaseDao  myBatisBaseDao;

    /**
     * 子类必须要给父类这个多态位置赋值
     * @param myBatisBaseDao
     */
    public void setMyBatisBaseDao(MyBatisBaseDao myBatisBaseDao) {
        this.myBatisBaseDao = myBatisBaseDao;
    }

    @Override
    public int deleteByPrimaryKey(PK id) {
        return this.myBatisBaseDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Model record) {
        return this.myBatisBaseDao.insert(record);
    }

    @Override
    public int insertSelective(Model record) {
        return this.myBatisBaseDao.insertSelective(record);
    }

    @Override
    public Model selectByPrimaryKey(PK id) {
        return (Model) this.myBatisBaseDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Model record) {
        return this.myBatisBaseDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Model record) {
        return this.myBatisBaseDao.updateByPrimaryKey(record);
    }
}
